<?php

require_once("./lib/pluginbase.php");

class RoulettePlugin extends PluginBase
{
	protected $chamber;
	function processChatCommand($name, $cmd, $args)
	{
		if($cmd == "!rr")
		{
			if (isset($this->chamber) && $this->chamber > 0)
			{
				switch ($this->chamber)
				{
					case 5:
						echo "say " . $name . " pulls the trigger...\n";
						break;
					case 4:
						echo "say " . $name . " pulls the trigger...\n";
						break;
					case 3:
						echo "say " . $name . " feels lucky and pulls the trigger...\n";
						break;
					case 2:
						echo "say " . $name . " takes a 50/50 chance and pulls the trigger...\n";
						break;
					case 1:
						echo "say " . $name . ", idiotically, pulls the trigger...\n"; 
						break;
				}
			}
			else
			{
				echo "say $name spins the cylinder and pulls the trigger...\n";
				$this->chamber = 6;
			}
			
			usleep(500000);
			
			if (rand(1, $this->chamber) == 1)
			{
				echo "say BANG! " . $name . " is killed!\n";
				usleep(500000);
				echo "kick " . $name . "\n";
				$this->chamber = 0;
			}
			else
			{
				echo "say CLICK! " . $name . " is lucky!\n";
				$this->chamber--;
			}
		}
	}
}

registerPlugin("roulette", new RoulettePlugin);


